#include "led.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/event_groups.h"
// static const char *TAG = "example";
void myled_init(){
    gpio_config_t io_conf;
    //配置输出
    // disable interrupt
    io_conf.intr_type = GPIO_INTR_DISABLE;
    // set as output mode
    io_conf.mode = GPIO_MODE_OUTPUT;
    // bit mask of the pins that you want to set,e.g.GPIO18/19
    io_conf.pin_bit_mask = GPIO_OUTPUT_PIN_SEL;
    // disable pull-down mode
    io_conf.pull_down_en = 0;
    // disable pull-up mode
    io_conf.pull_up_en = 0;
    // configure GPIO with the given settings
    gpio_config(&io_conf);

    //配置输入
    // interrupt of rising edge
    io_conf.intr_type = GPIO_INTR_POSEDGE;
    // bit mask of the pins, use GPIO4/5 here
    io_conf.pin_bit_mask = GPIO_INPUT_PIN_SEL;
    // set as input mode
    io_conf.mode = GPIO_MODE_INPUT;
    // enable pull-up mode
    io_conf.pull_up_en = 1;
    gpio_config(&io_conf);

    //设置中断到某个引脚
    // change gpio intrrupt type for one pin
    gpio_set_intr_type(GPIO_INPUT_IO_0, GPIO_INTR_ANYEDGE);
    printf("hellow=====================led init==================\r\n");
}

void wifitcpstatus(){
    gpio_reset_pin(statusLED);
    /* Set the GPIO as a push/pull output */
    gpio_set_direction(statusLED, GPIO_MODE_OUTPUT);
    while(1){  
        switch (led_control_flag)
        {
        case 1:
            vTaskDelay(1000 / portTICK_PERIOD_MS);
            gpio_set_level(statusLED, 1);
            break;
        case 2:
            vTaskDelay(1000 / portTICK_PERIOD_MS);
            gpio_set_level(statusLED, 0);
            break;
        case 3:
            gpio_set_level(statusLED, 0);
            vTaskDelay(1000 / portTICK_PERIOD_MS);
            gpio_set_level(statusLED, 1);
            vTaskDelay(1000 / portTICK_PERIOD_MS);
            break;
        default:
            break;
        }
        vTaskDelay(5000 / portTICK_PERIOD_MS);
    }
}

void wifi_connected(){
    gpio_reset_pin(LED_WARM);
    /* Set the GPIO as a push/pull output */
    gpio_set_direction(LED_WARM, GPIO_MODE_OUTPUT);
    gpio_set_level(LED_WARM, 1);
    return ;
}

void wifi_disconnected(){
    gpio_reset_pin(LED_WARM);
    /* Set the GPIO as a push/pull output */
    gpio_set_direction(LED_WARM, GPIO_MODE_OUTPUT);
    gpio_set_level(LED_WARM, 0);
    return ;
}

void tcp_connected(){
    gpio_reset_pin(LED_RED);
    /* Set the GPIO as a push/pull output */
    gpio_set_direction(LED_RED, GPIO_MODE_OUTPUT);
    gpio_set_level(LED_RED, 1);
    return ;
}

void tcp_disconnected(){
    gpio_reset_pin(LED_RED);
    /* Set the GPIO as a push/pull output */
    gpio_set_direction(LED_RED, GPIO_MODE_OUTPUT);
    gpio_set_level(LED_RED, 0);
    return ;
}

void led_on(gpio_num_t aa)
{
gpio_set_level(aa,1);
}

void led_off(gpio_num_t aa)
{
gpio_set_level(aa,0);
}


